﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MapgisEbp.QuickDataBase;
using Logistics.DataManage.Local;
using System.Data;

namespace Logistics.DataManage
{
    class BillLogsDAO
    {
        /// <summary>
        /// 操作日志信息的添加
        /// </summary>      
        /// <param name="userName">操作人用户名</param>
        /// <param name="eventName">操作时间名称</param>
        /// <param name="logInfor">操作详情</param>
        /// <param name="note">备注</param>
        public static void AddWaybillInforLogs(string userName, string WaybillID, string eventName, string logInfor, string note)
        {
            //SiteCode--时间类型(鄙视)
            //SiteType--事件说明(鄙视)
            String sql = "insert into WaybillLog (LogID,WaybillID,SiteCode,SiteType,CreateDate,CreateUser,Note,State,column1)" +
            "values(?,?,?,?,?,?,?,?,?)";
            String newLogId =  Guid.NewGuid().ToString().Replace("-","").Substring(0,20);//无语中
            ParameterizedSQL pSQL = LocalDb.Handler.DbAdapter.AdaptSQLAnonymousParams(sql,
                newLogId, WaybillID, eventName, logInfor, DateTime.Now, userName
 ,note, "0", WaybillID);
            LocalDb.Handler.ExecuteNonQuery(pSQL.SQL, pSQL.Parameters);
        }

        public static DataSet GetOperationLogs(String userName,DateTime start,DateTime end)
        {
            IList<object> paras = new List<Object>();
            paras.Add(start);
            paras.Add(end);
            String sql = "select * from WaybillLog where CreateDate>=? and CreateDate<? ";
            if (!String.IsNullOrEmpty(userName))
            {
                sql += " and CreateUser=?";
                paras.Add(userName);
            }
            ParameterizedSQL pSQL = LocalDb.Handler.DbAdapter.AdaptSQLAnonymousParams(sql, paras.ToArray());
            return LocalDb.Handler.ExecuteQuery(pSQL.SQL, pSQL.Parameters);
        }
    }
}
